<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://unpkg.com/vue"></script>
    <script>
        window.onload=function() {
            var app5 = new Vue({
                el: '#app-5',
                methods:{
                    reverseMessage: function () {
                        this.message = this.message.split('').reverse().join('')
                    },
                    addpeoples: function () {
                        var x={name:this.username, age:this.age,time:new Date()
                        };
                        this.peoples.push(x);
                    },
                    removeall:function() {this.peoples = [];
                    },
                    remove:function(index) {
                    this.peoples.splice(index,1);
                }

                },

                data: {
                    username:'',
                    age:null,
                    message: 'Hello Vue.js!',
                    peoples: [
                        {name: '小明', age: 30,time:new Date()},
                        {name: '小红', age: 40,time:new Date()},
                        {name: '小李', age: 50,time:new Date()},
                    ]
                },
                filters:{
                    times:function(val){
                        return(val.getHours() +":"+val.getMinutes()+":"+val.getSeconds());
                    },


                   names: function (value) {
                            if (!value) return ''
                            value = value.toString()
                            return value.charAt(0).toUpperCase() + value.slice(1)
                        }
                }

            })
        }



    </script>
</head>
<body>
<div id="app-5">
    <p>{{ message }}</p>
    <input v-model="username">
    <input v-model="age">
    <button v-on:click="addpeoples">添加</button>
    <button v-on:click="removeall">全部清空</button>

    <table border="1">
        <tr>
            <th>序号</th>
            <th>名字</th>
            <th>年龄</th>
            <th>添加时间</th>
            <th>操作</th>
        </tr>
        <tr v-for="(people,index) in peoples">
            <td>{{index+1}}</td>
            <td>{{people.name|names }}</td>
            <td>{{people.age }}</td>
            <td>{{people.time|times }}</td>
            <td><button  v-on:click="remove(index)">删除</button></td>

        </tr>
    </table>
</div>
</body>
</html>
